import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'

import * as ElementPlusIconsVue from '@element-plus/icons-vue'


const BASE_URL ='http://localhost:8080';
window.BASE_URL = BASE_URL;
const app = createApp(App)
app.config.globalProperties.BASE_URL = BASE_URL;
for (const [key, component] of Object.entries(ElementPlusIconsVue)){
    app.component(key, component)
}
app.use(ElementPlus,{ locale: zhCn }).use(store).use(router).mount('#app')

const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}
//7.定义获取当前登录人数据的全局方法
window.getUser = ()=>{
    //如果获取到了用户数据,则转回JS对象
    //如果没有获取到用户数据,转为布尔是false,值取null
    return localStorage.user ? JSON.parse(localStorage.user) : null;
}

